<?php
session_start();
?>

<html>
	<head>
		<title>Shopping</title>
		<style type="text/css">
			body{
				font:12px verdana;				
			}	
			.pro{
				border: 1px solid #999;
				margin: 5px;
				padding: 5px;
				width: 400px;
			}
			a{
				color: #666;
				text-decoration: none;
				font-weight: 900;
			}
			a:hover{
				text-decoration: underline;
			}
			#cart{
				border: 1px solid #999;
				margin: 5px;
				padding: 5px;
				width: 400px;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<h1>Shopping</h1>
		<div id="cart">
		<?php
			$ok = 0;
			if(isset($_SESSION['cart'])){
				foreach($_SESSION['cart'] as $k => $v){
					if (isset($v)) $ok = 1;
				}
			}
			if ($ok == 0){
				echo "<p>Ban khong co mon hang nao trong gio hang</p>";
			}else{
				$item = sizeof($_SESSION['cart']);
				echo "<p>Ban co <a href='cart.php'>". $item ." mon hang</a> trong gio hang</p>";
			}			
		?>
		</div>
		<?php
			$conn = mysql_connect('localhost','root','vertrigo') or die("can not connect to server");
			mysql_select_db('iblog', $conn);
			$sql = "select * from books order by id";
			$query = mysql_query($sql);
			if (mysql_num_rows($query)){
				while($row = mysql_fetch_array($query)){
					echo "<div class='pro'>";
					echo "<h3>".$row['title']."</h3>";
					echo "Tac gia: ". $row['author'] . " - Gia: " . number_format($row['price'], 3) . " VND<br/>";
					echo "<p align='right'><a href='addcart.php?item=". $row['id'] ."'>Mua sach nay</a></p>";
					echo "</div>";
				}
			}
		?>
	</body>
</html>
